package com.foreknow.dao.impl;

import com.foreknow.dao.AdminDao;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;
import com.foreknow.model.Admin;

import java.util.List;


public class AdminDaoImpl extends BaseDAO implements AdminDao {

    @Override
    public Admin getAdminByNameByPass(String adminName, String password) {
        String sql = "select * from admin where adminName=? and password=?";
        EntityMapping mapping = mappingFactory.getMap(MappingFactory.ADMIN_MAPPING);
        List<Object> query = jdbcTemplate.query(sql, mapping, adminName, password);
        if(query.size()>0) {
            Admin gb = (Admin) query.get(0);
            return gb;
        }
        return null;
    }

    @Override
    public boolean register(Admin admin) {
        String sql="insert into admin(adminName,password) values(?,?)";
        int i = jdbcTemplate.update(sql,admin.getAdminName(), admin.getPassword());
        return i!=0;
    }

}


